package net.cl.myweb.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MainServlet extends HttpServlet {

	private static final long serialVersionUID = 3080280770773537929L;

	@Override
	public void init(ServletConfig config) throws ServletException {
		System.setProperty("org.apache.catalina.SESSION_COOKIE_NAME", "_session");
		super.init(config);
	}

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter writer = null;
		try {
			writer = response.getWriter();
			writer.println(request.getHeader("User-Agent"));
			Date date=new Date();
			SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
			String time=df.format(date);
			writer.println(time);
			writer.flush();
		} catch (IOException e) {
			// e.printStackTrace();
		} finally {
			if (writer != null)
				writer.close();
		}
	}

}
